#include "progressbar.h"

ProgressBar::ProgressBar(QWidget *parent) : QWidget(parent)
{
    setFixedHeight(8);  // 设置进度条的高度
    currentValue = 0;   // 当前进度
    maxValue = 100;     // 最大进度值
}

void ProgressBar::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // 绘制背景
    painter.setPen(Qt::NoPen);
    painter.setBrush(QColor(220, 220, 220));
    painter.drawRect(rect());

    // 绘制进度
    painter.setBrush(Qt::red);
    qreal progressWidth = width() * (qreal(currentValue) / maxValue);
    painter.drawRect(QRectF(0, 0, progressWidth, height()));

    painter.setBrush(Qt::white);
    qreal circleRadius = height();
    qreal circleXPos = progressWidth - circleRadius / 2.0;
    painter.drawEllipse(QPointF(circleXPos, height() / 2.0), circleRadius / 2.0, circleRadius / 2.0);
}
